﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>字段权限</title>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <base target="_self" />
    <style type="text/css">
        th, td {
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        var frmID;
        var fk_flow;
        var fk_Node;
        $(function () {

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Sln");
            handler.AddUrlData();

            var data = handler.DoMethodReturnString("Fields_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            fieldsData = JSON.parse(data);

            var trStr = "";
            var UIVisible = true;
            var UIIsEnable = true;
            var IsSigan = true;
            var IsNotNull = true;
            var IsWriteToFlowTable = true;
            var IsWriteToGenerWorkFlow = true;

            for (var i = 0; i < fieldsData.length; i++) {
                fieldsData[i].IsChange = false;
                trStr += "<tr >";
                trStr += "<td class=Idx>" + (fieldsData[i].idx + 1) + "</td>";
                trStr += "<td>" + fieldsData[i].KeyOfEn + "</td>";
                trStr += "<td>" + fieldsData[i].Name + "</td>";
                trStr += "<td>" + fieldsData[i].LGTypeT + "</td>";
                trStr += "<td><input onkeydown='upischange(" + i + ");' id='" + i + "_" + fieldsData[i].KeyOfEn + "_RegularExp" + "' type='text' placeholder='输入有效的正则表达式' value='" + fieldsData[i].RegularExp + "'/></td>";
                trStr += "<td><input onkeydown='upischange(" + i + ");' id='" + i + "_" + fieldsData[i].KeyOfEn + "_DefVal" + "' type='text' placeholder='请输入默认值…' value='" + fieldsData[i].DefVal + "'/></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='UIVisible' id='" + i + "_" + fieldsData[i].KeyOfEn + "_UIVisible" + "' type='checkbox' " + (fieldsData[i].UIVisible ? "checked" : "") + ">可见</label></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='UIIsEnable' id='" + i + "_" + fieldsData[i].KeyOfEn + "_UIIsEnable" + "' type='checkbox' " + (fieldsData[i].UIIsEnable ? "checked" : "") + ">可用</label></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='IsSigan' id='" + i + "_" + fieldsData[i].KeyOfEn + "_IsSigan" + "' type='checkbox' " + (fieldsData[i].IsSigan ? "checked" : "") + ">签名</label></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='IsNotNull' id='" + i + "_" + fieldsData[i].KeyOfEn + "_IsNotNull" + "' type='checkbox' " + (fieldsData[i].IsNotNull ? "checked" : "") + ">必填</label></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='IsWriteToFlowTable' id='" + i + "_" + fieldsData[i].KeyOfEn + "_IsWriteToFlowTable" + "' type='checkbox' " + (fieldsData[i].IsWriteToFlowTable ? "checked" : "") + ">写入NDxxRpt</label></td>";
                trStr += "<td><label class='checkbox'><input onclick='checkclick(this," + i + ");' class='IsWriteToGenerWorkFlow' id='" + i + "_" + fieldsData[i].KeyOfEn + "_IsWriteToGenerWorkFlow" + "' type='checkbox' " + (fieldsData[i].IsWriteToGenerWorkFlow ? "checked" : "") + ">写入WF_GernrWorkFlow</label></td>";
                trStr += "</tr>";

                if (!fieldsData[i].UIVisible) {
                    UIVisible = false;
                }
                if (!fieldsData[i].UIIsEnable) {
                    UIIsEnable = false;
                }
                if (!fieldsData[i].IsSigan) {
                    IsSigan = false;
                }
                if (!fieldsData[i].IsNotNull) {
                    IsNotNull = false;
                }
                if (!fieldsData[i].IsWriteToFlowTable) {
                    IsWriteToFlowTable = false;
                }
                if (!fieldsData[i].IsWriteToGenerWorkFlow) {
                    IsWriteToGenerWorkFlow = false;
                }
                if (i == fieldsData.length - 1) {
                    trStr += "<tr >";
                    trStr += "<td colspan=\"12\"> <button onclick='dosave();' class='btn btn-primary' type='button' >保存</button></td>";
                    trStr += "</tr>";
                }
            }
            if (UIVisible) {
                $('#KeyOfEn_UIVisible')[0].checked = true;
            }
            if (UIIsEnable) {
                $('#KeyOfEn_UIIsEnable')[0].checked = true;
            }
            if (IsSigan) {
                $('#KeyOfEn_IsSigan')[0].checked = true;
            }
            if (IsNotNull) {
                $('#KeyOfEn_IsNotNull')[0].checked = true;
            }
            if (IsWriteToFlowTable) {
                $('#KeyOfEn_IsWriteToFlowTable')[0].checked = true;
            }
            if (IsWriteToGenerWorkFlow) {
                $('#KeyOfEn_IsWriteToGenerWorkFlow')[0].checked = true;
            }

            $("#Table1 tr:last").after(trStr);

        });
        var FieldsAttrs = new Object();
        var fieldsData = null;

        //保存字段方案
        function dosave() {

            var arr = new Array();
            for (var i = 0; i < fieldsData.length; i++) {
                if (fieldsData[i].IsChange) {
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_UIVisible").is(':checked')) {
                        fieldsData[i].UIVisible = true;
                    } else {
                        fieldsData[i].UIVisible = false;
                    }
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_UIIsEnable").is(':checked')) {
                        fieldsData[i].UIIsEnable = true;
                    } else {
                        fieldsData[i].UIIsEnable = false;
                    }
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_IsSigan").is(':checked')) {
                        fieldsData[i].IsSigan = true;
                    } else {
                        fieldsData[i].IsSigan = false;
                    }
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_IsNotNull").is(':checked')) {
                        fieldsData[i].IsNotNull = true;
                    } else {
                        fieldsData[i].IsNotNull = false;
                    }
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_IsWriteToFlowTable").is(':checked')) {
                        fieldsData[i].IsWriteToFlowTable = true;
                    } else {
                        fieldsData[i].IsWriteToFlowTable = false;
                    }
                    if ($('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_IsWriteToGenerWorkFlow").is(':checked')) {
                        fieldsData[i].IsWriteToGenerWorkFlow = true;
                    } else {
                        fieldsData[i].IsWriteToGenerWorkFlow = false;
                    }

                    fieldsData[i].DefVal = $('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_DefVal").val();
                    fieldsData[i].RegularExp = $('#' + fieldsData[i].idx + '_' + fieldsData[i].KeyOfEn + "_RegularExp").val();

                    arr.push(fieldsData[i]);
                }
            }

            if (arr.length == 0) {
                alert("没有检测到您修改了什么，无需更新");
                return;
            }

            var flowNo = GetQueryString("FK_Flow");
            var nodeID = GetQueryString("FK_Node");
            var frmID = GetQueryString("FK_MapData");

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=Fields_Save&FK_Flow=" + flowNo + "&FK_Node=" + nodeID + "&FK_MapData=" + frmID,
                dataType: 'json',
                data: { 'FieldsAttrsObj': JSON.stringify(arr) },
                success: function (data) {

                    //    alert(data);
                    //     upstate(false);
                    //     if (data.indexOf('err@') == 0) {
                    //       alert(data);
                    //      return;
                    //     //    }

                    alert("共更新" + data + "个字段信息");
                    window.location.href = window.location.href;

                }
            });
        }

        function replaceTrim(val) {//去除空格
            return val.replace(/[ ]/g, "");
        }

        function upischange(index) {
            fieldsData[index].IsChange = true;
        }
        //绑定是否全选或者取消全选
        function checkclick(o, index) {
            upischange(index);
            var ischeckedall = true;
            var rowstype = o.classList;
            $('.' + rowstype).each(function () {
                if (this.type == 'checkbox' && !this.checked) {
                    ischeckedall = false;
                    return ischeckedall;
                }
            });

            if (ischeckedall)
                $('#KeyOfEn_' + rowstype)[0].checked = true;
            else
                $('#KeyOfEn_' + rowstype)[0].checked = false;
        }

        //全选或者反选
        function CheckAll(rowstype) {
            $('.' + rowstype).each(function () {
                if (this.type == 'checkbox') {
                    $('#KeyOfEn_' + rowstype)[0].checked ? this.checked = true : this.checked = false;
                }
            });

            upstate(true);
        }

        function upstate(ischange) {
            for (var i = 0; i < fieldsData.length; i++) {
                fieldsData[i].IsChange = ischange;
            }
        }
    </script>
</head>
<body >
    <table id="Table1" >
    <caption> 节点-表单-字段权限 </caption>
        <tr>
            <th>序</th>
            <th>字段</th>
            <th>名称</th>
            <th>类型</th>
            <th>正则表达式</th>
            <th>默认值</th>
            <th><input onclick="CheckAll('UIVisible');" id='KeyOfEn_UIVisible' type="checkbox" /> <label for="KeyOfEn_UIVisible"> 可见 </label></th>
            <th><input onclick="CheckAll('UIIsEnable');" id='KeyOfEn_UIIsEnable' type='checkbox' /><label for="KeyOfEn_UIIsEnable"> 可用</label></th>
            <th><input onclick="CheckAll('IsSigan');" id='KeyOfEn_IsSigan' type='checkbox' /><label for="KeyOfEn_IsSigan"> 签名</label></th>
            <th><input onclick="CheckAll('IsNotNull');" id='KeyOfEn_IsNotNull' type='checkbox' /><label for="KeyOfEn_IsNotNull"> 必填</label></th>
            <th><input onclick="CheckAll('IsWriteToFlowTable');" id='KeyOfEn_IsWriteToFlowTable' type='checkbox' /><label for="KeyOfEn_IsWriteToFlowTable"> 写入流程数据表</label></th>
            <th><input onclick="CheckAll('IsWriteToGenerWorkFlow');" id='KeyOfEn_IsWriteToGenerWorkFlow' type='checkbox' /><label for="KeyOfEn_IsWriteToGenerWorkFlow"> 写入流程注册表</label></th>
        </tr>
    </table>
</body>
</html>
